﻿package com.best.oasis.settlement.biz.facade.security
{
	import com.best.oasis.flexbase.util.BeanUtils;
	import com.best.oasis.flexbase.util.tree.TreeNode;
	import com.best.oasis.settlement.biz.facade.base.SuperResponder;
	
	
	import com.best.oasis.settlement.biz.facade.base.OldBaseFacade;
	import com.best.oasis.settlement.common.error.ErrorCode;
	import com.best.oasis.settlement.common.model.ModelLocator;
	import com.best.oasis.settlement.common.vo.admin.authentication.AuthenticationVO;
	import com.best.oasis.settlement.common.vo.security.CheckedRoleTreeVO;
	import com.best.oasis.settlement.common.vo.security.UserVO;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	/**
	 * 权限操作类
	 * @author bl00064
	 * 
	 */	
	public class RoleFacade extends OldBaseFacade
	{
		
		/**
		 * 获取所有权限所构成的树
		 */	
		public function getRoleTree(groupId:Number, callback:Function):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					if(event.result != null){
						var result:CheckedRoleTreeVO = CheckedRoleTreeVO(event.result);
						if(callback != null){
							callback(result);
						}
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("获取权限数据失败！" + event.fault.faultString);
				});

			delegate.getCheckedRoleTree(groupId).addResponder(responder);
		}
		/**
		 * 获取当前角色组内的权限所构成的树
		 */	
		public function getSelectedRoleTree(groupId:Number, roleTreeNode:TreeNode, 
											callback:Function):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					if(event.result != null){
						var result:TreeNode = TreeNode(event.result);
						BeanUtils.copyProperties(roleTreeNode, result);
						if(callback != null){
							callback();
						}
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("获取权限数据失败！" + event.fault.faultString);
				});
		
			delegate.getSelectedRoleTree(groupId).addResponder(responder);
		}
		
	}
}